package y23.Oct;
class MyThread3 implements Runnable{
    String winner;
    public void run(){
        for (int i = 0; i <=100 ; i++) {
            if(Thread.currentThread().getName().equals("兔子")||i!=0&&i%10==0) {
                i += 5;
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            if (gameOver(i)){
                break;
            }
            System.out.println(Thread.currentThread().getName()+"前进了"+i+"步");
        }
    }

    public boolean gameOver(int i) {
        if(winner!=null){
            return true;
        }
        if (i >= 100) {
            winner = Thread.currentThread().getName();
            System.out.println("winnner:" + Thread.currentThread().getName());
            return true;
        }
        return false;
    }

}

public class Test22 {
    public static void main(String[] args) {
        MyThread3 myThread3 = new MyThread3();
        new Thread(myThread3,"兔子").start();
        new Thread(myThread3,"乌龟").start();
    }
}
